package org.hs.phd.odi.tracking.performanceevaluation;

import java.awt.Polygon;

import org.hs.phd.common.geometry.PolygonUtils;
import org.hs.phd.common.simpleplayer.ImageSequenceFrame;

public class F1ScoreMetric extends AbstractTrackingPerformanceMetric {

	@Override
	protected float compute(ImageSequenceFrame frame, Polygon groundTruthTrackShape, Polygon computedTrackShape) {
		
		double overlapArea = PolygonUtils.getPolygonalIntersectionArea(groundTruthTrackShape,computedTrackShape );
		
		double gtArea = PolygonUtils.getPolygonalArea(groundTruthTrackShape);
		double computedArea = PolygonUtils.getPolygonalArea(computedTrackShape);
		
		double recall = overlapArea/gtArea;
		double precision = overlapArea/computedArea;
		
		double f1Score = 2*precision*recall/(precision+recall);
		
		return (float)f1Score;
	}

	@Override
	public String getShortName() {
		return "F1Score";
	}

	@Override
	public String getName() {
		return "F1 Measure";
	}

	@Override
	public String getUnitName() {
		return "Ratio";
	}

	@Override
	public float getRangeMin() {
		return 0;
	}

	@Override
	public float getRangeMax() {
		return 1;
	}


}
